package com.bysc.commentservice.api;

import com.bysc.baseservice.handler.BaiYunException;
import com.bysc.commonutils.ResultCode;
import com.bysc.commonutils.Results;
import com.bysc.commonutils.constant.MessageConstant;
import com.bysc.commentservice.entity.vo.CollectVo;
import com.bysc.commentservice.service.GoodCollectApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "前台收藏功能")
@RestController
@RequestMapping("/goodservice/good-collect")
public class GoodCollectApiController {

    @Autowired
    private GoodCollectApiService goodCollectApiService;


    @ApiOperation(value = "收藏接口") //帖子，study
    @PostMapping("collectByToken")
    public Results collectByToken(
            @ApiParam(name = "collectVo",value = "收藏信息{文章id,文章类型}",required = true)
            @RequestBody CollectVo collectVo, HttpServletRequest request){
        try {
            goodCollectApiService.collectByToken(collectVo,request);
            return Results.ok().message(MessageConstant.COLLECT_SUCCESS);
        } catch (Exception e) {
            throw new BaiYunException(ResultCode.ERROR,MessageConstant.COLLECT_FAIL);
        }
    }


}
